package com.tianji.learning.controller;


import com.tianji.common.domain.R;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.dto.LearningPlanPageVO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.service.ILearningLessonService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import java.util.List;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author WFan
 * @since 2025-03-22
 */
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService learningLessonService;

    /**
     * 课程列表查询
     *
     * @return
     */
    @GetMapping("page")
    public R lessonsListQuery(PageQuery pageQuery) {
        return R.ok(learningLessonService.lesesonsListQuery(pageQuery));
    }

    /**
     * 最近学习课程
     *
     * @return
     */
    @GetMapping("now")
    public R nowLearningLesson() {
        LearningLessonVO nowLearningLesson = learningLessonService.nowLearningLesson();
        return R.ok(nowLearningLesson);
    }

    /**
     * 根据课程id删除课程
     */
    @DeleteMapping("{courseId}")
    public R deleteLessonByCourseId(@PathVariable Long courseId) {
        learningLessonService.deleteLessonCourseId(courseId);
        return R.ok();
    }

    /**
     * 检查课程是否有效
     */
    @GetMapping("{courseId}/valid")
    public Long checkLessonValid(@PathVariable Long courseId) {
        return learningLessonService.checkLessonValid(courseId);
    }

    /**
     * 查询用户课表中指定课程状态
     */
    @GetMapping("{courseId}")
    public LearningLessonVO checkLessonStatus(@PathVariable Long courseId) {
        return learningLessonService.checkLessonStatus(courseId);
    }

    /**
     * 统计课程的学习人数
     */
    @GetMapping("{courseId}/count")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId) {
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    ;

    /**
     * 创建/修改 学习计划
     */
    @PostMapping("plans")
    public void addLearningPlan(@RequestBody LearningPlanDTO learningPlanDTO) {
        learningLessonService.addLearningPlan(learningPlanDTO);
    }

    /**
     * 查询学习进度计划
     */
    @GetMapping("/plans")
    public LearningPlanPageVO queryLearningPlan(PageQuery pageQuery) {
        return learningLessonService.queryLearningPlan(pageQuery);
    }

}
